package com.doumuxie.linstener;


import com.doumuxie.dto.ConsumeDto;
import com.doumuxie.dto.ProductDto;
import com.doumuxie.frame.ProductConsumeFrame;
import com.doumuxie.handler.ProductConsumeHandler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author doumuxie https://gitee.com/doumuxie/
 * @version 1.0
 * @date 2020/9/26 9:00
 * @description 生产者消费者窗口事件
 **/
public class ProductConsumeListener implements ActionListener {

    private ProductConsumeFrame frame;

    public ProductConsumeListener(ProductConsumeFrame frame) {
        this.frame = frame;
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        if (source == frame.getCreateBtn()) {
            // 生成生产者 生成时间1-2S随机
            for (int i = 0; i < 7; i++) {
                ProductConsumeHandler.productDtoList.add(new ProductDto(frame));
            }
            // 生成消费者 消费时间2-3S随机
            for (int i = 0; i < 4; i++) {
                ProductConsumeHandler.consumeDtoList.add(new ConsumeDto(frame));
            }
            ProductConsumeHandler.drawProduct(frame);
        }
    }


}
